//
//  BaseViewController.m
//  NewProject
//
//  Created by admin on 2017/6/16.
//  Copyright © 2017年 李航飞. All rights reserved.
//

#import "BaseViewController.h"
#import <MBProgressHUD/MBProgressHUD.h>

@interface BaseViewController ()
@property (nonatomic, strong)UIButton *backButton;
@end

@implementation BaseViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    // 判断tabbar的显示隐藏
    if ([self.navigationController.childViewControllers.firstObject isEqual:self]) {
        // 是第一个页面
        [self.tabBarController.tabBar setHidden:NO];
        _backButton.hidden = YES;
    }else if ([[self.navigationController.childViewControllers.firstObject childViewControllers] containsObject:self]){
        // 是第一个页面的子vc
        _backButton.hidden = YES;
        [self.tabBarController.tabBar setHidden:NO];
    }else{
        _backButton.hidden = NO;
        [self.tabBarController.tabBar setHidden:YES];
    }
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    //导航栏左侧按钮
    [self.navigationItem setHidesBackButton:YES];
    
    _backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _backButton.frame = CGRectMake(5/WIDTH_6_SCALE, 0, 50, 50);
    [_backButton setImage:[UIImage imageNamed:@"返回箭头"] forState:UIControlStateNormal];
    [_backButton setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 24/WIDTH_6_SCALE)];
    [_backButton addTarget:self action:@selector(goBackAction) forControlEvents: UIControlEventTouchUpInside];
    UIBarButtonItem *back=[[UIBarButtonItem alloc]initWithCustomView:_backButton];
    UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    nagetiveSpacer.width = -7;//这个值可以根据自己需要自己调整
    self.navigationItem.leftBarButtonItems=@[nagetiveSpacer, back];

    // Do any additional setup after loading the view.
}

- (void)goBackAction{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)showTip:(NSString *)tipStr toView:(UIView *)view
{
    if (view == nil)
        view = [[UIApplication sharedApplication].windows lastObject];
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.label.text = tipStr;
    hud.label.numberOfLines = 0;
    // 设置图片
//    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    
    // 1秒之后再消失
    [hud hideAnimated:YES afterDelay:1.5];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
